<template>
  <div id="ECharts"></div>
</template>
<script>
import * as echarts from "echarts";
import { http } from "@/api/request";
export default {
  data() {
    return {};
  },
  methods: {},
  components: {},
  computed: {},
  watch: {},
  created() {},
  async mounted() {
    var list = [],
      addConfirm = [];
    let res = await http();
    var data = res.countryAddConfirmRankList;
    data.map(function (a, b) {
      list.push(a.nation);
      addConfirm.push(a.addConfirm);
    });
    // console.log(data);
    var chartDom = document.getElementById("ECharts");
    var myChart = echarts.init(chartDom);
    window.onresize = function() {
      myChart.resize()
    }
    var option = {
      title: {
        text: "新增确诊TOP10",
        x: "center",
        y: "4%",
        textStyle: {
          color: "#fff",
          fontSize: "22",
        },
        subtextStyle: {
          color: "#90979c",
          fontSize: "16",
        },
      },
      tooltip: {
        trigger: "axis",
        axisPointer: {
          type: "shadow",
        },
      },
      grid: {
        top: "15%",
        right: "3%",
        left: "10%",
        bottom: "12%",
      },
      xAxis: [
        {
          type: "category",
          data: list,
          axisLine: {
            lineStyle: {
              color: "rgba(255,255,255,0.12)",
            },
          },
          axisLabel: {
            margin: 10,
            color: "#e2e9ff",
            textStyle: {
              fontSize: 14,
            },
          },
        },
      ],
      yAxis: [
        {
          axisLabel: {
            formatter: "{value}",
            color: "#e2e9ff",
          },
          axisLine: {
            show: false,
            lineStyle: {
              color: "rgba(255,255,255,1)",
            },
          },
          splitLine: {
            lineStyle: {
              color: "rgba(255,255,255,0.12)",
            },
          },
        },
      ],
      series: [
        {
          type: "bar",
          data: addConfirm,
          barWidth: "10px",
          itemStyle: {
            normal: {
              color: new echarts.graphic.LinearGradient(
                0,
                0,
                0,
                1,
                [
                  {
                    offset: 0,
                    color: "rgba(0,244,255,1)", // 0% 处的颜色
                  },
                  {
                    offset: 1,
                    color: "rgba(0,77,167,1)", // 100% 处的颜色
                  },
                ],
                false
              ),
              barBorderRadius: [30, 30, 30, 30],
              shadowColor: "rgba(0,160,221,1)",
              shadowBlur: 4,
            },
          },
        },
      ],
    };
    option && myChart.setOption(option);
  },
};
</script>
<style lang="scss" scoped>
#ECharts {
  width: 100%;
  height: 100%;
  padding: 10px;
  box-sizing: border-box;
}
</style>
